package com.zcsy.manage.service.mall.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zcsy.manage.model.mall.GoodsCategory;
import com.zcsy.manage.persistence.mall.GoodsCategoryDao;
import com.zcsy.manage.service.mall.IGoodsCategoryService;

@Service
public class GoodsCategoryServiceImpl implements IGoodsCategoryService {

	@Autowired
	private GoodsCategoryDao goodsCategoryDao;
	
	@Override
	public int insert(GoodsCategory goodsCategory) {
		return goodsCategoryDao.insert(goodsCategory);
	}

	@Override
	public int update(GoodsCategory goodsCategory) {
		GoodsCategory oldCategory = goodsCategoryDao.getGoodsCategoryById(goodsCategory.getId());
		
		oldCategory.setName(goodsCategory.getName());
		oldCategory.setDescrip(goodsCategory.getDescrip());
		oldCategory.setLevel(goodsCategory.getLevel());
		oldCategory.setParentId(goodsCategory.getParentId());
		oldCategory.setIsNeedDistribute(goodsCategory.getIsNeedDistribute());
		oldCategory.setIsServicePrice(goodsCategory.getIsServicePrice());
		oldCategory.setIsNeedConfrim(goodsCategory.getIsNeedConfrim());
		
		return goodsCategoryDao.update(oldCategory);
	}

	@Override
	public int deleteByPrimaryKey(String id) {
		return goodsCategoryDao.deleteByPrimaryKey(id);
	}

	@Override
	public GoodsCategory getGoodsCategoryById(String id) {
		return goodsCategoryDao.getGoodsCategoryById(id);
	}

	@Override
	public List<GoodsCategory> getGoodsCategoryByKeyWord(
			GoodsCategory goodsCategory) {
		return goodsCategoryDao.getGoodsCategoryByKeyWord(goodsCategory);
	}

	@Override
	public List<GoodsCategory> getGoodsCategoryByLevel(Integer level) {
		return goodsCategoryDao.getGoodsCategoryByLevel(level);
	}

	@Override
	public List<GoodsCategory> getGoodsCategoryByParentId(String parentId) {
		return goodsCategoryDao.getGoodsCategoryByParentId(parentId);
	}

	@Override
	public List<GoodsCategory> getAllGoodsCategory() {
		return goodsCategoryDao.getAllGoodsCategory();
	}

	@Override
	public Boolean isLeaf(String categoryId) {
		return goodsCategoryDao.isLeaf(categoryId);
	}

	@Override
	public List<GoodsCategory> selectCategoryByShopId(String shopId) {
	    return goodsCategoryDao.selectCategoryByShopId(shopId);
	}
	
	@Override
	public String selectParentIdByGoodsId(String goodsId) {
		return goodsCategoryDao.selectParentIdByGoodsId(goodsId);
	}
}
